// 工作流编排对话型应用API类型定义

// 文件对象类型
export interface WorkflowFile {
  type: 'image' | 'audio' | 'video' | 'document';
  transfer_method: 'remote_url' | 'local_file' | 'upload_file';
  url?: string;
  upload_file_id?: string;
  file_name?: string;
  file_size?: number;
}

// 发送消息请求参数
export interface WorkflowChatRequest {
  inputs: Record<string, any>;
  query: string;
  response_mode: 'blocking' | 'streaming';
  conversation_id?: string;
  user?: string;
  files?: WorkflowFile[];
  model_config?: {
    pre_prompt?: string;
    [key: string]: any;
  };
}

// 流式响应数据块
export interface WorkflowStreamChunk {
  event: string;
  task_id: string;
  id: string;
  answer: string;
  // 解析后的扩展字段（从 answer 中拆分 <think> 思考过程 与 结果内容）
  reasoning?: string; // <think></think> 间的内容
  result?: string; // </think> 之后的内容
  reasoningEnded?: boolean; // 是否已出现 </think> 结束标签
  metadata: {
    usage: {
      total_tokens: number;
      prompt_tokens: number;
      completion_tokens: number;
    };
    conversation_id: string;
    user: string;
  };
  created_at: number;
}

// 阻塞响应
export interface WorkflowBlockingResponse {
  answer: string;
  conversation_id: string;
  created_at: number;
  id: string;
  metadata: {
    usage: {
      total_tokens: number;
      prompt_tokens: number;
      completion_tokens: number;
    };
    conversation_id: string;
    user: string;
  };
  task_id: string;
}

// 统一响应类型
export type WorkflowChatResponse = WorkflowBlockingResponse | Response;

// 消息历史记录
export interface WorkflowMessage {
  role: 'user' | 'assistant';
  content: string;
  created_at?: number;
}

// 会话信息
export interface WorkflowConversation {
  id: string;
  user?: string;
  created_at?: number;
  updated_at?: number;
  title?: string;
  last_message?: string;
}

// v1 messages 列表记录
export interface WorkflowHistoryMessage {
  id: string;
  conversation_id: string;
  inputs?: Record<string, any>;
  query?: string;
  answer?: string;
  message_files?: any[];
  feedback?: any;
  retriever_resources?: any[];
  created_at?: number; // 秒级时间戳
}
